package animation.wlh.com.animation_demo.demo

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.LayoutInflater
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Scroller
import android.widget.Toast
import animation.wlh.com.animation_demo.R
import animation.wlh.com.animation_demo.ScrollListView
import animation.wlh.com.animation_demo.ScrollListView.ListScrollListener
import kotlinx.android.synthetic.main.activity_slide_anim1.*
import java.util.*

/**
 * Created by weilh on 2016/1/26.
 */
class SlideAnimAct1 : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_slide_anim1)
        title = "滑动特效"
        var itemList = ArrayList<String>()
        for (i in 1..50) {
            itemList.add("" + i)
        }
        list.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, itemList)
        list.setListener(object : ListScrollListener {
            override fun scroll(y: Float) {
                var scrollResult = root_view.scrollY-y
                if (scrollResult > 200) {
                    scrollResult = 200f
                } else if (scrollResult < 0) {
                    scrollResult = 0f
                }
                root_view.scrollTo(0, scrollResult.toInt())
            }

            override fun scrollEnd() {
                if (root_view.scrollY > 100) {
                    root_view.scrollTo(0, 200)
                } else {
                    root_view.scrollTo(0,0)
                }
            }
        })
    }
}